/**
 * Created by zhanglihe on 15/11/19.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'collection',
    'template',
    'model'
], function ($, common, ready, Collection, template, Model) {
    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            loading();
            this.fetch();
            this.event();
        },

        fetch: function () {
            var _this = this;
            this.collection = new Collection({
                url: _global.url.api + 'site/withdraws',
                condition: {limit: 10, offset: 0},
                model: {
                    event: {
                    }
                },
                callback: function () {
                    loaded();
                }
            });
            this.collection.fetch();
        },

        event: function () {
            var _this = this;
            /**
             * 按状态查询
             */
            $('#btn-status').find('a').on('click', function (e) {
                e.preventDefault();
                _this.collection.condition.status = $(e.target).attr('rel');
                _this.collection.reload();
                $(e.target).addClass('active').siblings().removeClass('active');
            });

            $('#btn-excel').on('click', function() {
                var href = $(this).attr('href');
                if(typeof _this.collection.condition.status !== 'undefined') {
                    href += '?status=' + _this.collection.condition.status;
                }
                $(this).attr('href', href);
            });
        }
    };

    new index();

});